#include "infectionprotection.h"

#include <QPalette>

InfectionProtection::InfectionProtection(QWidget *parent)
    : QWidget(parent)
{
    // Make the game full screen
    setWindowState(Qt::WindowFullScreen);

    resize(QApplication::desktop()->size());

    // Set the background of the screen to be pure black, just in case of a render problem
    QPalette newPalette (palette());
    newPalette.setColor(QPalette::Background,Qt::black);
    setPalette(newPalette);

    lastScene = GameScene::menuScene;
    currentScene = GameScene::menuScene;

    //setup menu scene
    menuScene = new MenuScene(this);
    QObject::connect(menuScene,SIGNAL(end(GameScene::GameScenes)),this,SLOT(sceneOver(GameScene::GameScenes)));
    menuScene->startScene();

    //setup the help scene
    helpScene = new HelpScene(this);
    QObject::connect(helpScene,SIGNAL(end(GameScene::GameScenes)),this,SLOT(sceneOver(GameScene::GameScenes)));

    SoundPlayer::setResourceDirectory(RESOURCE_DIR + "/sounds");
    SoundPlayer::loopSound("36734__sagetyrtle__citystreet3", -1);
}

InfectionProtection::~InfectionProtection()
{

}

void InfectionProtection::sceneOver(GameScene::GameScenes nextScene)
{    
    if (nextScene == GameScene::previousScene)
    {
        GameScene::GameScenes tempScene = currentScene;
        currentScene = lastScene;
        lastScene = tempScene;
    }
    else
    {
        lastScene = currentScene;
        currentScene = nextScene;
    }

    if (currentScene == GameScene::endGame)
        close();

    else if (currentScene == GameScene::levelSceneTutorial)
    {
        tutorial = new TutorialLevel(this);
        connect(tutorial, SIGNAL(end(GameScene::GameScenes)), this, SLOT(sceneOver(GameScene::GameScenes)));
        tutorial->startScene();
    }

    else if (currentScene == GameScene::levelScene1)
    {
        level1 = new Level1(this);
        QObject::connect(level1,SIGNAL(end(GameScene::GameScenes)),this,SLOT(sceneOver(GameScene::GameScenes)));
        level1->startScene();
    }

    else if (currentScene == GameScene::levelScene2)
    {
        level2 = new Level2(this);
        QObject::connect(level2,SIGNAL(end(GameScene::GameScenes)),this,SLOT(sceneOver(GameScene::GameScenes)));
        level2->startScene();
    }

    else if (currentScene == GameScene::levelScene3)
    {
        level3 = new Level3(this);
        QObject::connect(level3,SIGNAL(end(GameScene::GameScenes)),this,SLOT(sceneOver(GameScene::GameScenes)));
        level3->startScene();
    }

    else if (currentScene == GameScene::helpScene)
        helpScene->startScene();

    else if (currentScene == GameScene::menuScene)
        menuScene->startScene();
}
